<template>
  <div id="bars" style="width: 1400px; height: 450px"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: {
    datas: Array,
  },
  data() {
    return {
      options: {},
      charts: "",
    };
  },
  mounted() {
    this.options = {
      dataset: {
        source: this.datas,
      },
      title: {
        text: "年度作物对比",
      },
      xAxis: {
        // data: dataAxis,
        type: "category",
        axisLabel: {
          inside: true,
          textStyle: {
            // color: "#fff",
          },
        },
        axisTick: {
          show: false,
        },
        axisLine: {
          show: false,
        },
        z: 10,
      },
      yAxis: {
        axisLine: {
          show: false,
        },
        axisTick: {
          show: false,
        },
        axisLabel: {
          textStyle: {
            color: "#999",
          },
        },
      },
      dataZoom: [
        {
          type: "inside",
        },
      ],
      series: [
        {
          type: "bar",
          seriesLayoutBy: "row",
          showBackground: true,
          //   seriesLayoutBy: "row",
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: "#e92758" },

              { offset: 1, color: "#ff9569" },
            ]),
          },
          emphasis: {
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#e92758" },
                { offset: 0.7, color: "#e92758" },
                { offset: 1, color: "#ff9569" },
              ]),
            },
          },
          //   data: data,
        },
        {
          type: "bar",
          seriesLayoutBy: "row",
          showBackground: true,
          //   seriesLayoutBy: "row",
          itemStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
              { offset: 0, color: "#83bff6" },
              { offset: 0.5, color: "#188df0" },
              { offset: 1, color: "#188df0" },
            ]),
          },
          emphasis: {
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#2378f7" },
                { offset: 0.7, color: "#2378f7" },
                { offset: 1, color: "#83bff6" },
              ]),
            },
          },
          //   data: data,
        },
      ],
      legend: {
        show: true,
      },
    };
    this.charts = echarts.init(document.getElementById("bars"));
    this.charts.setOption(this.options);
  },
  watch: {
    datas: {
      handler(nd) {
        console.log(nd);
        this.options.dataset.source = nd;
        this.charts.setOption(this.options);
      },
    },
  },
};
</script>

<style>
</style>